package com.ai3d.rfid.common.event

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.ai3d.rfid.common.proxy.MMKVProxy
import com.ai3d.rfid.common.proxy.MMKVProxy.KEY_EVENT_UPLOAD_TIME
import com.bj.disc.service.UploadEventsService
import com.blankj.utilcode.util.GsonUtils
import com.ym521.logdog.LogDog
import java.util.concurrent.TimeUnit

/**
 * @ProjectName : disc
 * @Author : weijinsong
 * @Time : 2023/7/6 23:29
 * @Description : 文件描述
 */
class TimeTickReceiver : BroadcastReceiver() {
    companion object {
        private const val TAG = "TimeTickReceiver"

        fun register(context: Context?, receiver: TimeTickReceiver) {
            val filter = IntentFilter()
            filter.addAction(Intent.ACTION_TIME_TICK)
            context?.registerReceiver(receiver, filter)
        }
    }

    override fun onReceive(context: Context, intent: Intent) {
//        if (Intent.ACTION_TIME_TICK == intent.action && System.currentTimeMillis() - MMKVProxy.getLong(
//                KEY_EVENT_UPLOAD_TIME,
//                0
//            ) > TimeUnit.MINUTES.toMillis(5)
//        ) {
            //每一分钟更新时间
            MMKVProxy.setLong(KEY_EVENT_UPLOAD_TIME, System.currentTimeMillis())
            var loginToken = MMKVProxy.getString(MMKVProxy.KEY_TOKEN)
            if (null != loginToken && loginToken.isNotEmpty()) {
                LogDog.debug("TimeTickReceiver","onReceive:")
                try{
                    EventMgs.realEventReport()
                }catch (ex:Exception){

                }

            }
//        }
    }



}